"""
@date: 2023/7/25
@author: North
@desc: test
回合制游戏：两个人进入到房间，两个人会相互攻击

创建role类：
    name：
    blood（初始100）：
    credits（初始100）;
    atk(随机掉血):

创建Room类：
    房间名，编号，房间成员，最大人数
    自动开始人数

创建Game类：
    创建角色、添加角色到房间，满员开始
"""
import random


class Role:
    def __init__(self, name):
        self.name = name
        self.blood = 100

    def atk(self, other):
        if self.blood > 0:
            atk_num = random.randint(10, 30)
            # 可以判断一下当前的血量和要掉血的量
            other.blood -= atk_num
            print(f"{self.name}造成{atk_num}伤害{other.name}还剩余{other.blood}")
            if other.blood <= 0:
                print(f"{other.name}死亡")
        else:
            print(f"{self.name}已经死亡无法攻击")

    def add_atk(self):
        pass
    def __repr__(self):
        return f"{self.name}"

class Room:
    # MAX
    def __init__(self, No, name, max):
        self.No = No
        self.max = max
        self.name = name
        self.nums = []

    def add_role(self, role):
        if len(self.nums) < self.max:
            self.nums.append(role)
            print(f"欢迎{role.name}进入{self.No}号房间")
        else:
            print("房间已满，请加入其他房间")

    def start(self):
        if len(self.nums) == self.max:
            print("开始游戏！！！")
            print(f"当前房间有{len(self.nums)}个人：{self.nums}")
            role1 = self.nums[0]
            role2 = self.nums[1]
            while role1.blood > 0 and role2.blood > 0:
                operation = input("输入操作（1:攻击role1、2:攻击role2）:")
                if operation == "1":
                    role2.atk(role1)
                elif operation == "2":
                    role1.atk(role2)
        else:
            print("房间人员未满")


class Game:
    def __init__(self):
        pass

    def play(self):
        role1 = Role("role1")
        role2 = Role("role2")
        room1 = Room("001", "room1", 2)
        room1.add_role(role1)
        room1.add_role(role2)
        room1.start()

if __name__ == "__main__":
    game = Game()
    game.play()

